package com.iwop.moto.controller;

import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.MTrademarkService;
import com.iwop.moto.service.OrderRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2016/8/29.
 */
@Controller
public class OrderRefundController  extends  BaseController {

    @Autowired
    OrderRefundService orderRefundService;

    /**
     *****************************
     * 功能:添加退款
     * gw 2016-8-25 10:13:02
     * 参数:sid 品牌ID
     * 参数:apply_time 退款申请时间
     * 参数:refund_price 退款金额
     * 参数:refund_type 退款类型
     * 参数 refund_content 退款内容
     * 参数:refund_status 退款状态[0:退款中][1:同意退款][2:拒绝退款]
     * 参数:status_time 退款状态更新时间
     */
    @RequestMapping("/api/refund/add")
    @ResponseBody
    public ResultModel orderRefundAdd(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            String sid = UUID.randomUUID().toString();
            SRModel.put("sid", sid);
            SRModel.put("apply_time",new Date());
            SRModel.put("refund_status","0");
            orderRefundService.inserTorderRefund(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     *****************************
     * 功能:修改
     * gw 2016-8-25 10:13:02
     * 参数:sid 订单ID
     * 参数:apply_time 退款申请时间
     * 参数:refund_price 退款金额
     * 参数:refund_type 退款类型
     * 参数:refund_status 退款状态[0:退款中][1:同意退款][2:拒绝退款]
     * 参数:status_time 退款状态更新时间
     */
    @RequestMapping("/api/refund/edit")
    @ResponseBody
    public ResultModel orderRefundEdit(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel.put("status_time",new Date());
            orderRefundService.updateMOrderRefund(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    @RequestMapping("/api/refund/get")
    @ResponseBody
    public ResultModel getOrderRefund(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SuperRecordModel orderRefund = orderRefundService.getOrderRefund(SRModel.getString("order_no"));
            return getSucceed(orderRefund,ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }
}
